package com.qf.mvc2202.controller;

import com.qf.mvc2202.entity.User;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;

@Controller
@RequestMapping("/param")
public class ParamController {
    //http://localhost:8080/mvc2202/param/test1?id=100&name=luffy&gender=false&birth=2001/03/07 12:12:12
    @RequestMapping("/test1")
    public String test1(
            Integer id,
            String name,
            Boolean gender,
           @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date birth
    ){
        System.out.println(id);
        System.out.println(name);
        System.out.println(gender);
        System.out.println(birth);
        return "/hello.jsp";
    }
    @RequestMapping("/test2")
    public String test2(User user){
        System.out.println(user);
        return "/hello.jsp";
    }
    @RequestMapping("/test3")
    public String test3(String[] hobby){
        for (String s : hobby) {
            System.out.println(s);
        }
        return "/hello.jsp";
    }
    @RequestMapping("/get/{id}")
// @PathVariable将{id}路径匹配到值赋给id参数
// 路径名和参数名相同则@PathVariable("id")可简写为 @PathVariable
    public String test4(@PathVariable("id") Integer id){
        System.out.println("id:"+id);
        return "/hello.jsp";
    }
}
